﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Supervise_SuperInfo : System.Web.UI.Page,HZ.MBSM.BLL.IPageDescribe
{
    Int64 AccountId_Supervise;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (HZ.MBSM.BLL.Login.CheckAssert(UseAccountType))
        {
            if (!IsPostBack)
            {
                string strSql;
                System.Text.StringBuilder strHtml = new System.Text.StringBuilder();

               
                HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
                if (_Account != null)
                {
                    AccountId_Supervise = SysFun.ToLong(_Account.AccountId);
                    strSql = "select supervise.*,area.areaname from supervise left join area on supervise.AreaId=Area.AreaId where AccountId=" + AccountId_Supervise;
                    Db db = new Db();
                    System.Data.IDataReader dr = db.DataReader(strSql);
                    while (dr.Read())
                    {
                        txtAccountId.Text = dr["AccountId"].ToString();
                        txtAccountId.Visible = false;

                        strHtml.Append("<input type='text' value='" + dr["AreaName"].ToString() + "' name='AreaName' NotNull=\"所属地区\" />");
                        strHtml.Append("<input type='text' name='AreaId' value=" + dr["AreaId"].ToString() + " style='display: none'/>");
                        //strHtml.Append("<a href='javascript:AreaSelect(530000)'>选择地区</a>");
                        LabArea.Text = strHtml.ToString();
                        strHtml.Remove(0, strHtml.Length);
                        switch (SysFun.ToTrim(dr["Class"]))
                        {
                            case "1":
                                {
                                    strHtml.Append("<input type='radio' runat='server' id='RadioButton1'name='RdoClass' value='1' checked >省级");
                                    strHtml.Append("<input type='radio' runat='server' id='RadioButton2' name='RdoClass' value='2'>市级");
                                    strHtml.Append("<input type='radio' runat='server' id='RadioButton2' name='RdoClass' value='3'>县级");
                                    break;
                                }
                            case "2":
                                {
                                    strHtml.Append("<input type='radio' runat='server' id='RadioButton1'name='RdoClass' value='1' >省级");
                                    strHtml.Append("<input type='radio' runat='server' id='RadioButton2' name='RdoClass' value='2' checked >市级");
                                    strHtml.Append("<input type='radio' runat='server' id='RadioButton2' name='RdoClass' value='3'>县级");
                                    break;
                                }
                            default:
                                {
                                    strHtml.Append("<input type='radio' runat='server' id='RadioButton1'name='RdoClass' value='1' >省级");
                                    strHtml.Append("<input type='radio' runat='server' id='RadioButton2' name='RdoClass' value='2'>市级");
                                    strHtml.Append("<input type='radio' runat='server' id='RadioButton2' name='RdoClass' value='3' checked >县级");
                                    break;
                                }

                        }
                        LabClass.Text = strHtml.ToString();
                        txtAddress.Text = dr["Address"].ToString();
                        txtUserCode.Text = SysFun.ToTrim(dr["UserCode"]);
                        txtEmail.Text = dr["Email"].ToString();
                        txtFax.Text = dr["Fax"].ToString();
                        txtNetAddress.Text = dr["NetAddress"].ToString();
                        txtPostCode.Text = dr["PostCode"].ToString();
                        txtSuperviseMan.Text = dr["SuperviseMan"].ToString();
                        txtSuperviseName.Text = dr["SuperviseName"].ToString();
                        txtTelephone.Text = dr["Telephone"].ToString();
                        txtRegistDate.Text = dr["RegistDate"].ToString();
                        txtRegistDate.Visible = false;
                    }
                    dr.Close();
                    dr.Dispose();
                    db.Close();
                }
            }
        }
    }
    protected void BtnSave_Click(object sender, EventArgs e)
    {
        string strclass = Request.Form["RdoClass"].ToString(), strAreaId = Request.Form["AreaId"].ToString();
        AccountId_Supervise = SysFun.ToLong(txtAccountId.Text);
        int rowCun = 0;
        Db db1 = new Db();
        System.Data.IDataReader dr;
        String strSql = "select count(accountid) as cun from dbo.v_account where ( dwname= '" + SysFun.ToTrim(txtSuperviseName.Text) + "' or usercode='" + SysFun.ToTrim(txtUserCode.Text) + "') and AccountId <>" + AccountId_Supervise.ToString();
        dr = db1.DataReader(strSql);
        if (dr.Read())
        {
            rowCun = SysFun.ToInt(dr["cun"]);
        }
        dr.Close();
        dr.Dispose();
        db1.Close();
        if (rowCun > 0)
        {
            Response.Write("<script language=JavaScript>alert('该用户在数据库中已经存在！！！');</script>");
        }
        else
        {
            HZ.MBSM.DBUtility.Db db = new HZ.MBSM.DBUtility.Db(false);
            Grove.ORM.ObjectOperator oo = db.GetObjectOperator();

            HZ.MBSM.Model.Supervise Supervise = (HZ.MBSM.Model.Supervise)oo.Retrieve(typeof(HZ.MBSM.Model.Supervise), AccountId_Supervise);
            Supervise.UserCode = SysFun.ToTrim(txtUserCode.Text);
            Supervise.Address = SysFun.ToTrim(txtAddress.Text);
            Supervise.AreaId = SysFun.ToInt(strAreaId);
            Supervise.Class = strclass;
            Supervise.Email = SysFun.ToTrim(txtEmail.Text);
            Supervise.Fax = SysFun.ToTrim(txtFax.Text);
            Supervise.NetAddress = SysFun.ToTrim(txtNetAddress.Text);
            Supervise.PostCode = SysFun.ToTrim(txtPostCode.Text);
            //Supervise.RegistDate = Convert.ToDateTime(txtRegistDate.Text.ToString());
            Supervise.SuperviseMan = SysFun.ToTrim(txtSuperviseMan.Text);
            Supervise.SuperviseName = SysFun.ToTrim(txtSuperviseName.Text);
            Supervise.Telephone = SysFun.ToTrim(txtTelephone.Text);
            oo.Update(Supervise);
            oo.Dispose();
            db.Close();
            Response.Write("<script>alert('修改成功！！！');</script>");
            Response.Write("<script>window.location='SuperInfo.aspx';</script>");
        }  
    }

    #region IPageDescribe 成员

    public string Name
    {
        get { return "监督机构基本信息"; }
    }

    public string Describe
    {
        get { return ""; }
    }

    public string ParentName
    {
        get { return "监督机构基本信息"; }
    }
    

    public System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> UseAccountType
    {
        get
        {
            System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumSupervise);
            return _AccountType;
        }
    }

    #endregion
}
